<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
    <style>
        * {
            margin: 0;
            padding: 0;
        }

        .upload-container {
            width: 100%;
            overflow: hidden;
        }

        .add-image {
            width: 50px;
            height: 50px;
            margin: 30px auto;
            line-height: 50px;
            text-align: center;
            position: relative;
            box-sizing: border-box;
            border-radius: 3px;
            border: 1px solid #ccc;
        }

        #fileBtn {
            position: absolute;
            top: 0;
            left: 0;
            width: 50px;
            height: 50px;
            opacity: 0;
        }

        .show-image {
            width: 320px;
            padding: 10px;
            margin: 0 auto;
            box-sizing: border-box;
            overflow: hidden;
        }

        .show-image .image-item {
            width: 100px;
            height: 100px;
            box-sizing: border-box;
            padding: 0 10px;
            display: flex;
            align-items: center;
            background: #fff;
            float: left;
        }

        .show-image img {
            width: 100%;
        }

        .loading {
            position: fixed;
            top: 0;
            left: 0;
            right: 0;
            bottom: 0;
            background: rgba(0, 0, 0, .1);
        }

        .hide {
            display: none;
        }

        .loading-gif {
            position: absolute;
            top: 50%;
            left: 50%;
            transform: translate3d(-50%, -50%, 0);
        }
    </style>
</head>

<body>
    <div class="upload-container">
        <div class="add-image">Add
            <input type="file" id="fileBtn" accept="image/jpg,image/jpeg,image/png,image/gif">
        </div>
        <div class="show-image">

        </div>
    </div>
    <div class="loading hide" id="loading">
        <div class="loading-gif">
            <img src="./images/loading.gif" width="40">
        </div>
    </div>
</body>
<script src="./js/exif.js"></script>
<script src="./js/upload.js"></script>
<script src="./js/jquery-3.2.1.min.js"></script>
<script>
    var image = {
        imageList: [],
        imageNameList: [],
        uploadLIst: []
    };

    $('#fileBtn').on('change', function (event) {
        var e;

        e = event || window.event
        Uploader(e.target.files[0], function (imageInfo) {

            // 清空value保证用户在删除了上一次上传的照片以后可以继续上传上一次的照片
            e.target.value = null;

            // 如果上传的照片已经上传过 不再上传
            if (image.imageNameList.join("").indexOf(imageInfo.fileName) !== -1) return alert(
                "该图片已经上传过，请勿重复上传");

            image.imageList.push(imageInfo.imageSrc)
            image.imageNameList.push(imageInfo.fileName)
            image.uploadLIst.push(imageInfo.base64)

            $(".show-image").append('<div class="image-item"><img src="' + imageInfo.imageSrc +
                '"></div>')

        }, 10)
    })

    $(".show-image").on("click", ".image-item", function () {
        var index = $(this).index()

        $(this).remove()
        image.imageList.splice(index, 1)
        image.imageNameList.splice(index, 1)
        image.uploadLIst.splice(index, 1)
    })
</script>

</html>